#!/usr/bin/env python3
# -*- coding:utf-8 -*- 
import pymongo
from pymongo import MongoClient
from bson.json_util import dumps
import urllib
import time,datetime
import pymysql.cursors

db = MongoClient("10.211.55.10",27017)
testDB=db.test

conn= pymysql.connect(
        host='127.0.0.1',
        port = 3306,
        user='root',
        # passwd='123456',
        db ='housing_sales_test',
        charset='utf8mb4',
        cursorclass=pymysql.cursors.DictCursor
        )
mysqlCursor = conn.cursor()

cursor=testDB.car.find(filter={},projection={'_id': False}).skip(212800).batch_size(100)
print('查询%s数'%cursor.count())
i=0
try:
    while cursor.alive:
        for doc in cursor:
            i=i+1
            #print(dumps(doc))
            mysqlCursor.execute("insert into test1 (`u`)values(%s)", (dumps(doc)))
            time.sleep(0.00002)
            if (i%100)==0:
                conn.commit()
except Exception,e:
    print e
finally:
    mysqlCursor.close()
    conn.close()